/*eslint-disable*/
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const webpackBar = require('webpackbar')
const { merge } = require('webpack-merge')

const commonConfig = require('./webpack.common.js')

module.exports = merge(commonConfig, {
    mode: 'development',
    devtool: 'cheap-module-eval-source-map',
    output: {
        publicPath: '/'
    },
    module: {
        rules: [{
            test: /\.css$/,
            loader: [
                'style-loader',
                {
                    loader: 'css-loader',
                    options: {
                        sourceMap: true,
                        importLoaders: 1
                    }
                },
                'postcss-loader'
            ]
        }, {
            test: /\.less$/,
            loader: [
                'style-loader',
                {
                    loader: 'css-loader',
                    options: {
                        sourceMap: true,
                        importLoaders: 2
                    }
                },
                'postcss-loader',
                'less-loader'
            ]
        }]
    },
    devServer: {
        hotOnly: true,
        contentBase: path.resolve('./public'),
        compress: true,
        host: 'localhost',
        port: '8080',
        open: true,
        overlay:  {
            warnings: false,
            errors: true
        },
        publicPath: '/',
        // proxy: {},
    },
    plugins: [
        new webpackBar(),
        new webpack.DefinePlugin({'process.env.NODE_ENV': '"development"'}),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NamedModulesPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new HtmlWebpackPlugin({
            title: 'vue-app',
            templateParameters: {
                'BASE_URL': './'
            },
            filename: 'index.html', 
            template: path.resolve(__dirname, './public/index.html'), 
            inject: true
        }),
        new FriendlyErrorsPlugin()
    ]
})